package com.example.community.list;

import com.example.community.dao.ComtyDao;
import com.example.community.dao.FloorDao;
import com.example.community.model.Comty;
import com.example.community.model.Floor;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 楼栋管理
 */
@WebServlet(urlPatterns = "/floorListServlet")
public class FloorListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer ys = null;
        if (req.getParameter("ys")==null){
            ys = 1 ; //当前页数
        }else {
            ys = Integer.parseInt(req.getParameter("ys"));
        }
        int shuju = 8; //每页显示数据个数


        FloorDao floorDao = new FloorDao();
        List<Floor> floors = floorDao.fandLimit(ys,shuju);
        for (Floor floor:floors){
            ComtyDao comtyDao = new ComtyDao();
            Comty comty = comtyDao.fandById(floor.getCtNo());
            floor.setCtName(comty.getCtName());
        }
        Integer totalPageNum = floorDao.selectLimitCount(shuju);
        req.setAttribute("floors",floors);
        req.setAttribute("totalPageNum",totalPageNum);
        req.setAttribute("ys",ys);
        req.getRequestDispatcher("/WEB-INF/houseManager/floorList.jsp").forward(req,resp);
    }
}
